import 'package:flutter/material.dart';

import '../pages/address_book/address_book_view.dart';
import '../pages/find/find_view.dart';
import '../pages/message/home_view.dart';
import '../pages/personal_center/personal_center_view.dart';

class AtiButtonBar extends StatefulWidget {
  const AtiButtonBar({super.key, required this.title});
  final String title;

  @override
  State<AtiButtonBar> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<AtiButtonBar> {
  int _selectedIndex = 0;
  // 底部导航栏的页面内容
  static const List<Widget> _widgetOptions = <Widget>[
    HomeView(),
    AddressBookView(),
    FindView(),
    PersonalCenterView(),
  ];

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // appBar: AppBar(title: Text('Flutter Bottom Navigation with Page Stack')),
      body: IndexedStack(
        index: _selectedIndex, // 显示当前选中的页面
        children: _widgetOptions, // 页面列表
      ),
      bottomNavigationBar: BottomNavigationBar(
        backgroundColor: Colors.red,
        type: BottomNavigationBarType.fixed,
        currentIndex: _selectedIndex,
        onTap: _onItemTapped,
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'),
          BottomNavigationBarItem(icon: Icon(Icons.search), label: 'Search'),
          BottomNavigationBarItem(
            icon: Icon(Icons.account_circle),
            label: 'Profile',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.account_circle),
            label: 'Profile2',
          ),
        ],
      ),
    );
  }
}
